﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class GetBaseDataItemListAction : GetAction<Params.GetBaseDataItemListParams,
        Results.GetBaseDataItemListResult>
    {
        protected override ActionResult<Results.GetBaseDataItemListResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.GetBaseDataItemListParams opParams)
        {
            ServiceResult<List<BaseDataItem>> serviceResult = new BaseDataService().GetItemList(opParams.SummaryId);

            Results.GetBaseDataItemListResult actionResult = new Results.GetBaseDataItemListResult();
            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {

                for (int index = 0; index < serviceResult.Data.Count; index++)
                {
                    Results.GetBaseDataItemListResult.Item acResult = new Results.GetBaseDataItemListResult.Item();
                    acResult.Code = serviceResult.Data[index].Code;
                    acResult.Caption = serviceResult.Data[index].Caption;

                    actionResult.Add(acResult);
                }

                return new ActionResult<Results.GetBaseDataItemListResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.GetBaseDataItemListResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
